<template>
  <div class="page-box">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.definitionName" :placeholder="$t('process.name')"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle"
              @sort-change="dataListSortChangeHandle" style="width: 100%">
      <!--      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>-->
      <el-table-column prop="processDefinitionName" :label="$t('process.processDefinitionName')" header-align="center"
                       align="center"></el-table-column>
      <el-table-column prop="taskName" :label="$t('process.taskName')" header-align="center"
                       align="center"></el-table-column>
      <el-table-column prop="startUserName" :label="$t('process.startUserId')" header-align="center"
                       align="center"></el-table-column>
      <el-table-column prop="createTime" :label="$t('process.createTime')" header-align="center"
                       align="center"></el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="scope.row.processDefinitionKey == 'process_warning_pic'" type="text" size="small"
                     :processInstanceId="processInstanceId"
                     @click="taskHandle(scope.row, 'warning')">
            {{ $t("manage") }}
          </el-button>
          <el-button v-else-if="scope.row.processDefinitionKey == 'sensor_warning_handle'" type="text" size="small"
                     :processInstanceId="processInstanceId"
                     @click="ensortaskHandle(scope.row, 'warning')">
            {{ $t("manage") }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total"
                   layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle"
                   @current-change="pageCurrentChangeHandle"></el-pagination>
  </div>

  <WarningDataFrom ref="warningdatafrom" @close="close"></WarningDataFrom>
  <SensorWarningDataFrom ref="sensorwarningdatafrom" @close="close"></SensorWarningDataFrom>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import {defineComponent, nextTick, reactive, toRefs} from "vue";
import {IObject} from "@/types/interface";
import WarningDataFrom from "@/views/flow-warning/warningDataFrom.vue";
import SensorWarningDataFrom from "@/views/KxSensorUnusual/warningDataFrom.vue";

export default defineComponent({
  components: {
    WarningDataFrom,
    SensorWarningDataFrom
  },
  setup() {
    const state = reactive({
      getDataListURL: "/flow/common/todo/page",
      getDataListIsPage: true,
      activatedIsNeed: true,
      dataForm: {
        definitionName: "",
        taskId: ""
      },
      processInstanceId: ""
    });
    return {...useView(state), ...toRefs(state)};
  },
  created() {
    this.getDataList();
  },
  methods: {
    close() {
      this.getDataList();
    },
    // 处理
    taskHandle(row: IObject, picType: string) {
      nextTick(() => {
        if (picType === "warning") {
          this.$refs.warningdatafrom.init(row, "processing");
        } else {
          this.$refs.warningdatafrom.init(row);
        }
      });
    },
    ensortaskHandle(row: IObject, picType: string) {
      nextTick(() => {
        this.$refs.sensorwarningdatafrom.init(row, "processing");
      });
    }
  }
});
</script>

<style lang="scss" scoped>
.handel-p {
  text-align: right;
  margin: 0;
}
</style>

